package com.ulife.song.module.screen;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.ulife.common.exception.ManagerException;
import com.ulife.song.dao.dataobject.SongDO;
import com.ulife.song.manager.SongManager;

public class SongList {

	private static final Logger log = LoggerFactory.getLogger(SongList.class);
	
	@Autowired
	private SongManager songManager;
	
	@SuppressWarnings("unchecked")
	public void execute(Context context, Navigator nav) {
		List<SongDO> songList;
		try {
			songList = (List<SongDO>) context.get("songs");
			if (songList == null) {
				songList = songManager.getAllSong();
				
				if (CollectionUtils.isNotEmpty(songList)) {
					context.put("songs", songList);
				}
			}
		} catch (ManagerException e) {
			log.error("get song error", e);
		}
		
		context.put("module", "song");
	}
}
